home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / AUDIO.ZIP / PHASER.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-12-11  |  8.8 KB  |  271 lines

  1. *
  2. *
  3. * phaser.asm
  4. *
  5. *
  6.  
  7. *
  8. *   Knobs - adjust these values within suggested range for
  9. *           variations on the effect.
  10. *
  11. *   Patch Name          Dry     Wet     FB     Top     Bottom   Speed
  12. *   Basic phase        07fffh  07fffh  00000h  0f000h   07ff0h   0008h
  13. *  Phase w/ FB        07fffh  07fffh  05000h  0f000h   07800h   0006h
  14. *   Med. phase        07fffh  07fffh  00000h  0f000h   07800h   0020h
  15. *   Fast phase        07fffh  07fffh  00000h  00000h   07000h   0050h
  16. * Invert w/ invert FB 07fffh  08000h  0a000h  0f000h   07400h   0002h
  17. *
  18. DRY_LEVEL       .set    07fffh  ; (0 - 07fffh dry signal level)
  19. WET_LEVEL       .set    07fffh  ; (08000h - 7fffh wet signal level)
  20. FB_LEVEL        .set    01000h  ; (08000h - 7fffh regeneration amount)
  21. SWEEP_TOP       .set    0f000h  ; top end of sweep range (0f000 - 0800h)
  22. SWEEP_BOT       .set    07800h  ; bottom end of sweep range (07ff0h - 0900h)
  23. SWEEP_SPEED     .set    00012h  ; rate of sweep (01h - 080h)
  24.  
  25. *
  26. *   Data storage
  27. *
  28. SPEED           .set    00h ; storage for SWEEP_SPEED param
  29. WET             .set    01h ; storage for WET_LEVEL
  30. DRY             .set    02h ; storage for DRY_LEVEL
  31. FEEDBACK        .set    03h ; storage for FB_LEVEL
  32. COEF_HI         .set    04h ; coefficient of filter
  33. COEF_LO         .set    05h ; fractional part of coefficient
  34. LX1             .set    06h ; filter states
  35. LY1             .set    07h ;       .
  36. LX2             .set    08h ;       .
  37. LY2             .set    09h ;       .
  38. LX3             .set    0ah ;       .
  39. LY3             .set    0bh ;       .
  40. LX4             .set    0ch ;       .
  41. LY4             .set    0dh ;       .
  42. TMP             .set    0eh ; temp register
  43. INPUT           .set    0fh ; dry input
  44. OUTPUT          .set    10h ; output of filter chain
  45. IOREG           .set    11h ; filter in/out reg
  46. INC_LO          .set    12h ; coefficient inc/dec value LSW
  47. INC_HI          .set    13h ; ditto but MSW
  48. SWEEPDIR        .set    14h ; track direction of sweep
  49. LOOKUP          .set    15h ; lookup table index
  50.  
  51.         .include "setup.asm"
  52.         
  53. *
  54. *                               main
  55. *
  56. main:
  57.         ssxm                    ; set sign extension mode
  58.         spm     1               ; set P shift for Q15 (1 bit left shift
  59.                                 ; from P => accum)
  60.         sovm                    ; set clipping overflow mode for
  61.                                 ; "analog" processing
  62.         ldpk    8               ; data at 0x400
  63.         
  64.         lalk    SWEEP_SPEED     ; sweep rate
  65.         sacl    SPEED
  66.         lalk    FB_LEVEL
  67.         sacl    FEEDBACK        ; delayed signal feedback mix
  68.         lalk    WET_LEVEL
  69.         sacl    WET             ; delayed signal output mix
  70.         lalk    DRY_LEVEL
  71.         sacl    DRY             ; straight signal output mix
  72.         lalk    01000h          ; midrange value
  73.         sacl    COEF_HI
  74.         lack    0
  75.         sacl    INC_LO
  76.         sacl    INC_HI
  77.         sacl    SWEEPDIR        ; initially down in frequency
  78.         lack    014h            ; enable AIC recv interrupts
  79.         ldpk    0
  80.         sacl    IMR
  81.         ldpk    8
  82.         
  83.         ; loop here forever processing interrupts
  84. loop:   idle
  85.         b       loop
  86.  
  87.         ; table of sweep adjustment factors
  88. SWEEPTAB:
  89.         .word   11970
  90.         .word   11600
  91.         .word   10890
  92.         .word   9700
  93.         .word   8200
  94.         .word   6300
  95.         .word   3950
  96.         .word   1000
  97.         .word   1000
  98.         .word   1000        
  99.         .word   1000
  100.         .word   1000
  101.         .word   1000
  102.         .word   1000
  103.         .word   1000
  104.         .word   12330
  105.         
  106. *
  107. *                               rint
  108. *
  109. *   Recv interrupt handler performs all the work. Since there is
  110. *   no main thread, there is no need to save or restore regs.
  111. *
  112. *   Difference equation is:
  113. *
  114. *   Y = COEF * (X + LY) - LX
  115. *
  116. *   Where:
  117. *       X = input value
  118. *       Y = output
  119. *       LX = last input
  120. *       LY = last output
  121. *
  122. rint:
  123.         ; note: no need to save/restore processor state since
  124.         ; main thread does absolutely nothing
  125.         sovm
  126.         
  127.         ; read in and store new input value
  128.         ldpk    0
  129.         lac     DRR
  130.         ldpk    8
  131.         sfr                     ; dump lowest 2 junk bits
  132.         sfr
  133.         sacl    IOREG
  134.         sacl    INPUT           ; keep copy of dry input
  135.  
  136.         ; do feedback before entering filters
  137.         lt      OUTPUT          ; get last output value
  138.         mpy     FEEDBACK
  139.         pac
  140.         addh    INPUT           ; filter input value is ready
  141.         sach    IOREG           ; pass to filter both in IOREG and accum
  142.                 
  143.         ; do first filter section
  144.         addh    LY1             ; add last Y
  145.         sach    TMP
  146.         lt      COEF_HI         ; scale sum by COEF
  147.         mpy     TMP
  148.         pac                     ; move to accum
  149.         subh    LX1             ; subtract last X
  150.         sach    LY1             ; output Y is ready, save in LY
  151.         lar     AR1,IOREG       ; save X in LX
  152.         sar     AR1,LX1
  153.         sach    IOREG           ; pass to next filter
  154.                 
  155.         ; do first second section
  156.         addh    LY2             ; add last Y
  157.         sach    TMP
  158.         lt      COEF_HI         ; scale sum by COEF
  159.         mpy     TMP
  160.         pac                     ; move to accum
  161.         subh    LX2             ; subtract last X
  162.         sach    LY2             ; output Y is ready, save in LY
  163.         lar     AR1,IOREG       ; save X in LX
  164.         sar     AR1,LX2
  165.         sach    IOREG           ; pass to next filter
  166.                 
  167.         ; do third filter section
  168.         addh    LY3             ; add last Y
  169.         sach    TMP
  170.         lt      COEF_HI         ; scale sum by COEF
  171.         mpy     TMP
  172.         pac                     ; move to accum
  173.         subh    LX3             ; subtract last X
  174.         sach    LY3             ; output Y is ready, save in LY
  175.         lar     AR1,IOREG       ; save X in LX
  176.         sar     AR1,LX3
  177.         sach    IOREG           ; pass to next filter
  178.  
  179.         ; do fourth filter section
  180.         addh    LY4             ; add last Y
  181.         sach    TMP
  182.         lt      COEF_HI         ; scale sum by COEF
  183.         mpy     TMP
  184.         pac                     ; move to accum
  185.         subh    LX4             ; subtract last X
  186.         sach    LY4             ; output Y is ready, save in LY
  187.         lar     AR1,IOREG       ; save X in LX
  188.         sar     AR1,LX4
  189.         sach    IOREG           ; pass to next filter
  190.         sach    OUTPUT          ; save filter chain's output value
  191.         
  192.         ; do level scaling on direct and wet
  193.         lt      OUTPUT
  194.         mpy     WET             ; scale wet signal
  195.         pac
  196.         lt      INPUT           ; get original input value
  197.         mpy     DRY             ; scale dry signal
  198.         apac                    ; generate composite final output
  199.         sach    TMP
  200.         lac     TMP             ; prepare final output for AIC
  201.         andk    0fffch          ; clear lowest 2 bits
  202.         ldpk    0
  203.         sacl    DXR             ; do output
  204.         ldpk    8
  205.  
  206.         ; adjust the coefficient
  207.         rovm                    ; normal arithmetic
  208.         lac     COEF_LO         ; 32 bit add
  209.         add     INC_LO
  210.         sacl    COEF_LO
  211.         sovm
  212.         lac     COEF_HI
  213.         addc    INC_HI
  214.         sacl    COEF_HI
  215.         rovm
  216.         ; see if we hit the upper or lower bounds of the sweep
  217.         lac     SWEEPDIR
  218.         bz      down
  219.         lalk    SWEEP_TOP
  220.         sub     COEF_HI
  221.         blez    adj_inc
  222.         lack    0               ; gonna start going down in freq
  223.         sacl    SWEEPDIR
  224.         b       reverse
  225. down:
  226.         lalk    SWEEP_BOT
  227.         sub     COEF_HI
  228.         bgz     adj_inc
  229.         lack    1               ; gonna start going up in freq
  230.         sacl    SWEEPDIR
  231. reverse:
  232.         lac     SPEED           ; reverse the sweep
  233.         neg                     ; by swapping sign of speed value
  234.         sacl    SPEED
  235. adj_inc:
  236.         ; adjust the increment value based on region of sweep
  237.         rsxm
  238.         lac     COEF_HI,4       ; get high nibble into accum high 0-3
  239.         sach    LOOKUP
  240.         ssxm
  241.         lalk    SWEEPTAB
  242.         add     LOOKUP
  243.         tblr    TMP             ; read the value from table into TMP
  244.         lt      TMP             ; multiply adjustment factor
  245.         mpy     SPEED           ; by sweep
  246.         pac
  247.         sacl    INC_LO          ; new 32 bit increment value
  248.         sach    INC_HI
  249. done:
  250.         eint
  251.         ret
  252.  
  253.  
  254. *
  255. *                               tint
  256. *
  257. *   Timer interrupt - not used.
  258. *
  259. tint:
  260.         eint
  261.         ret
  262.  
  263. *
  264. *                               xint
  265. *
  266. *   AIC xmit interrupt - not used.
  267. *       
  268. xint:
  269.         eint
  270.         ret
  271.